package com.mida.app.report.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mida.app.report.service.RequestFormBmsSvc;
import com.mida.bms.requestform.api.RegisterRequestApi;
import com.mida.bms.requestform.api.RequestFormApi;
import com.mida.bms.requestform.dto.RequestDiagnosisSetDto;
import com.mida.bms.requestform.dto.RequestPageInfoDto;
import com.mida.bms.requestform.dto.ServiceInstanceInfoDto;
import com.mida.bms.requestform.request.PatientRecordVo;
import com.mida.bms.requestform.request.RequestCustomerVO;
import com.mida.bms.requestform.request.RequestFormInfo;
import com.mida.bms.requestform.request.RequestListInfoVO;
import com.mida.bms.requestform.request.reqeustfrom.RegistrationListRequest;
import com.mida.bms.requestform.request.reqeustfrom.RequestServiceInstasnceRequest;
import com.mida.bms.requestform.response.QueryPatientMedicalReportVo;
import com.mida.bms.requestform.response.QueryPatientMedicalVo;
import com.mida.bms.requestform.vo.register.RegisterRequestInfo;
import com.mida.bms.requestform.vo.register.RegisterRequestVo;
import com.mida.bms.requestform.vo.register.RequestExamTechVo;
import com.mida.bms.requestform.vo.register.dto.RequestInfoCondition;
import com.mida.bms.requestform.vo.requestform.ApntRequestLifeCycleVo;
import com.mida.bms.requestform.vo.requestform.RequestCheckService;
import com.mida.bms.requestform.vo.requestform.ServiceInstanceVo;
import com.mida.tool.common.ret.RespBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 申请单域Api实现
 *
 * @author Peng.Wu
 * @version version-1.0
 * @date 2021/6/22 13:48
 */
@Service
public class RequestFormBmsSvcImpl implements RequestFormBmsSvc {

    private RequestFormApi requestFormApi;
    private RegisterRequestApi registerRequestApi;

    @Autowired
    public RequestFormBmsSvcImpl(RequestFormApi requestFormApi, RegisterRequestApi registerRequestApi) {
        this.requestFormApi = requestFormApi;
        this.registerRequestApi = registerRequestApi;
    }

    @Override
    public List<RegisterRequestInfo> findRequestInfoByCondition(RequestInfoCondition reqCondition) {
        RespBody<List<RegisterRequestInfo>> reqInfos = registerRequestApi.findRequestInfoByCondition(reqCondition);
        if (CollectionUtils.isNotEmpty(reqInfos.getData())) {
            return reqInfos.getData();
        }
        return null;
    }

    @Override
    public void updateCheckServicesByRequestSoId(RequestCheckService reqCheckSvc) {
        registerRequestApi.updateCheckServicesByRequestSoId(reqCheckSvc);
    }

    @Override
    public void manualRegisterRequest(RegisterRequestVo registerRequestVo) {
        registerRequestApi.manualRegisterRequest(registerRequestVo);
    }

    @Override
    public void updateRequestExamTech(RequestExamTechVo examTechVo) {
        registerRequestApi.updateRequestExamTech(examTechVo);
    }

    @Override
    public List<ServiceInstanceInfoDto> getReqeustServiceInstanceVos(List<RequestServiceInstasnceRequest> requests) {
        RespBody<List<ServiceInstanceInfoDto>> respBody = requestFormApi.getReqeustServiceInstanceVos(requests);
        if (CollectionUtils.isNotEmpty(respBody.getData())) {
            return respBody.getData();
        }
        return null;
    }

    @Override
    public RespBody<List<RequestDiagnosisSetDto>> getRequestDiagnosisWithRequestSoids(List<String> requestSoids) {
        return requestFormApi.getRequestDiagnosisWithRequestSoids(requestSoids);
    }

    /**
     * 获取申请单分页数据
     * @param registrationListRequest
     * @return
     */
    @Override
    public RespBody<Page<RequestPageInfoDto>> getRequestPageInfoWithCondition(RegistrationListRequest registrationListRequest) {
        return requestFormApi.getRequestPageInfoWithCondition(registrationListRequest);
    }

    @Override
    public RespBody<Map<BigDecimal, List<ServiceInstanceInfoDto>>> getBigDecimalListMap(List<BigDecimal> requestSoids) {
        return requestFormApi.getBigDecimalListMap(requestSoids);
    }

    @Override
    public Boolean insertRequestLifeCycle(ApntRequestLifeCycleVo apntRequestLifeCycle) {
        return requestFormApi.insertRequestLifeCycle(apntRequestLifeCycle).getData();
    }

    @Override
    public List<ServiceInstanceVo> findServiceInstancesByRequestSoid(String requestSoid) {
        RespBody<List<ServiceInstanceVo>> respBody = requestFormApi.findServiceInstancesByRequestSoid(requestSoid);
        if (CollectionUtils.isNotEmpty(respBody.getData())) {
            return respBody.getData();
        }
        return null;
    }

    @Override
    public QueryPatientMedicalVo queryPatientMedicalByRequestSoid(BigDecimal requestSoid,
                                                                  BigDecimal msdServiceInstanceSoid) {
        RespBody<QueryPatientMedicalVo> respBody =
                requestFormApi.queryPatientMedicalByRequestSoid(requestSoid, msdServiceInstanceSoid);
        if (null != respBody.getData()) {
            return respBody.getData();
        }
        return null;
    }

    @Override
    public QueryPatientMedicalReportVo queryRequestInfoByRequestSoidForResport(BigDecimal requestSoid) {
        RespBody<QueryPatientMedicalReportVo> respBody = requestFormApi.queryRequestInfoByRequestSoidForResport(requestSoid);
        if (null != respBody.getData()) {
            return respBody.getData();
        }
        return null;
    }

    @Override
    public RespBody<List<RequestServiceInstasnceRequest>> queryServiceByRequestSoidAndSerivceSoid(List<RequestServiceInstasnceRequest> list) {
        return requestFormApi.queryServiceByRequestSoidAndSerivceSoid(list);
    }

    @Override
    public Boolean updatePatientRecord(PatientRecordVo patientRecord) {
        return requestFormApi.updatePatientRecord(patientRecord).getData();
    }

    @Override
    public BigDecimal findRequestServiceSoid(BigDecimal requestSoid, BigDecimal msdServiceInstanceSoid) {
        return requestFormApi.findRequestServiceSoid(requestSoid, msdServiceInstanceSoid).getData();
    }

    @Override
    public RespBody<Page<RequestListInfoVO>> getRequestListInfo(RequestFormInfo request) {
        return requestFormApi.getRequestListInfo(request);
    }

    @Override
    public RespBody<RequestCustomerVO> getRequsetByRequisitionId(BigDecimal requisitionId) {
        return requestFormApi.getRequsetByRequisitionId(requisitionId);
    }

}
